<?php
 class CronModel extends Model
 {
     public function add($zym_10)
     {
         $zym_10['create_user_id'] = $_SESSION['admin']['userid'];
         $zym_10['create_time'] = NOW_TIME;
         $zym_10['update_user_id'] = $_SESSION['admin']['userid'];
         $zym_10['update_time'] = NOW_TIME;
         $zym_9 = $this->insert($zym_10);
         return $zym_9;
     }
     public function edit($zym_10)
     {
         $zym_10['update_user_id'] = $_SESSION['admin']['userid'];
         $zym_10['update_time'] = NOW_TIME;
         $zym_9 = $this->update($zym_10);
         dc::rm('cron', $zym_10['id']);
         return $zym_9;
     }
     public function del($zym_11)
     {
         dc::rm('cron', $zym_11['id']);
         return $this->where($zym_11)->delete();
     }
     public function getlist()
     {
         $zym_8 = (array)$this->select();
         foreach ($zym_8 as &$zym_6) {
             if ($zym_6['action'] == 'cron/task/collect') {
                 $zym_6['param'] = '&ruleid=' . $zym_6['param'];
             } else {
                 $zym_6['param'] = '';
             }
             $zym_6['create_username'] = dc::get('user', $zym_6['create_user_id'], 'name');
             $zym_6['update_username'] = dc::get('user', $zym_6['update_user_id'], 'name');
             $zym_6['url_edit'] = U('cron.manage.edit', array('id' => $zym_6['id']));
             $zym_6['create_time'] = $zym_6['create_time'] ? date('Y-m-d H:i', $zym_6['create_time']) : '';
             $zym_6['update_time'] = $zym_6['update_time'] ? date('Y-m-d H:i', $zym_6['update_time']) : '';
         }
         return $zym_8;
     }
     public function run()
     {
         if (C('cron_power')) {
         }
     }
     public function getpower()
     {
         $zym_7 = include APP_PATH . '/common/config.php';
         return $zym_7['cron_power'];
     }
     public function check()
     {
         if ($this->getpower()) {
             if (cache::get('cron_master_starttime') + 60 < NOW_TIME) {
                 if (!empty($_GET['debug'])) {
                     echo 'cron reload time:' . date('Y-m-d H:i:s', cache::get('cron_master_time')) . ' now:' . date('Y-m-d H:i:s') . '<br />';
                 }
                 cache::set('cron_master_pid', rand(1, 10000));
                 cache::set('cron_master_time', 0);
                 cache::set('cron_master_runtime', 0);
                 cache::set('cron_master_starttime', NOW_TIME);
                 $zym_5 = $this->config->get('cronurl') ?: $this->config->get('siteurl');
                 http::trigger($zym_5 . U('cron.task.master', array('backRun' => 1)));
                 if (!empty($_GET['debug'])) {
                     var_dump($zym_5 . U('cron.task.master', array('backRun' => 1)));
                 }
                 return false;
             } else {
                 if (!empty($_GET['debug'])) {
                     echo 'pid:' . cache::get('cron_master_pid') . '<br />';
                     echo 'master启动时间：' . date('Y-m-d H:i:s', cache::get('cron_master_time')) . '<br />';
                     echo 'master运行时间：' . date('Y-m-d H:i:s', cache::get('cron_master_runtime')) . '<br />';
                     echo 'master初始启动时间：' . date('Y-m-d H:i:s', cache::get('cron_master_starttime')) . '<br />';
                 }
                 return true;
             }
         } elseif (!empty($_GET['debug'])) {
             echo 'cron is stop!';
             return true;
         }
     }
 }
